package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.InsuranceGoodsVoucherDao;
import com.x.erp.manage.InsuranceGoodsVoucherManage;
import com.x.erp.model.InsuranceGoodsVoucher;
import com.x.erp.model.InsuranceOrder;
import com.x.erp.rpc.InsuranceGoodsVoucherRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 延保商品使用券服务
 */
@Component
@Service(interfaceName = "com.x.erp.rpc.InsuranceGoodsVoucherRpcService", timeout = 60000)
public class InsuranceGoodsVoucherService extends BaseService implements InsuranceGoodsVoucherRpcService {

	@Autowired
	private InsuranceGoodsVoucherDao insuranceGoodsVoucherDao;

	@Autowired
	private InsuranceGoodsVoucherManage insuranceGoodsVoucherManage;

	/**
	 * 查询延保商品使用券列表
	 *
	 * @param insuranceGoodsVoucher
	 * @return
	 */
	@Override
	public List<InsuranceGoodsVoucher> selectVoucherList(InsuranceGoodsVoucher insuranceGoodsVoucher) {
		try {
			return insuranceGoodsVoucherDao.selectVoucherList(insuranceGoodsVoucher);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询延保商品使用券数量
	 *
	 * @param insuranceGoodsVoucher
	 * @return
	 */
	@Override
	public int selectVoucherNum(InsuranceGoodsVoucher insuranceGoodsVoucher) {
		try {
			return insuranceGoodsVoucherDao.selectVoucherNum(insuranceGoodsVoucher);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 修改延保商品使用券列表（核销）
	 *
	 * @param insuranceGoodsVouchers
	 * @return
	 */
	@Override
	public int updateVoucherList(InsuranceOrder insuranceOrder, List<InsuranceGoodsVoucher> insuranceGoodsVouchers) {
		try {
			return insuranceGoodsVoucherManage.updateVoucherList(insuranceOrder, insuranceGoodsVouchers);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
}
